package com.jiezuo.flowable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiezuo.flowable.entity.MyFormInformation;
import com.jiezuo.flowable.mapper.MyFormInformationMapper;
import com.jiezuo.flowable.service.MyFormInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author 庞留杰
 * @version V1.0
 * @description 动态表单信息记录表
 * @date 2024/03/27 10:03
 **/
@Transactional
@Slf4j
@Service
public class MyFormInformationServiceImpl extends ServiceImpl<MyFormInformationMapper, MyFormInformation> implements MyFormInformationService {


    @Autowired
    MyFormInformationMapper mapper;

    @Override
    public IPage<MyFormInformation> findPage(Page initMpPage, MyFormInformation myFormInformation) {
        QueryWrapper<MyFormInformation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        return this.page(initMpPage, queryWrapper);
    }

    @Override
    public List<MyFormInformation> findList(MyFormInformation myFormInformation) {
        QueryWrapper<MyFormInformation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        List<MyFormInformation> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public MyFormInformation findById(String id) {
        return this.getById(id);
    }

    @Override
    public boolean add(MyFormInformation myFormInformation) {
        return this.save(myFormInformation);
    }

    @Override
    public boolean update(MyFormInformation myFormInformation) {
        return this.updateById(myFormInformation);
    }

    @Override
    public boolean delete(String id) {
        MyFormInformation myFormInformation = new MyFormInformation();
        myFormInformation.setId(id);
        myFormInformation.setIs_delete("1");
        return this.updateById(myFormInformation);
    }

    @Override
    public boolean updateFormBusinessIdById(Map<String, Object> params) {
        String id = String.valueOf(params.get("id"));
        String businessId = String.valueOf(params.get("businessId"));
        Boolean boo = mapper.updateFormBusinessIdById(id, businessId);
        return boo;
    }
}
